package com.xinghen.amqp.rabbitmq;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author xinghen
 * @ClassName: RabbitMqConfig
 * @Package: com.xinghen.amqp.rabbitmq
 * @Description RabbitMq配置
 * @create 2017-12-08 15:28
 */
@Configuration
public class RabbitMqConfig {


    /**
     * rabbitListenerContainerFactoryPlus
     *
     * @param rabbitListenerContainerFactory
     * @param jackson2JsonMessageConverter
     * @return
     */
    @Bean
    public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactoryPlus(
            SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory,
            Jackson2JsonMessageConverter jackson2JsonMessageConverter) {
        rabbitListenerContainerFactory.setMessageConverter(jackson2JsonMessageConverter);
        return rabbitListenerContainerFactory;
    }

    /**
     * jackson2JsonMessageConverter
     *
     * @param objectMapper
     * @return
     */
    @Bean
    public Jackson2JsonMessageConverter jackson2JsonMessageConverter(ObjectMapper objectMapper) {
        return new Jackson2JsonMessageConverter(objectMapper);
    }

}
